package com.example.cloudpracticeplatform.service.impl;

import com.example.cloudpracticeplatform.entity.Statistics;
import com.example.cloudpracticeplatform.mapper.StatisticsMapper;
import com.example.cloudpracticeplatform.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;

@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    private StatisticsMapper statisticsMapper;

    // 获取基础统计数据
    @Override
    public Statistics getBasicStatistics() {
        return new Statistics.Builder()
                .setTotalTeachers(statisticsMapper.countTeachers())
                .setTotalCourses(statisticsMapper.countCourses())
                .setTotalStudents(statisticsMapper.countStudents())
                .setTotalEnrollments(statisticsMapper.countEnrollments())
                .setTotalContainers(statisticsMapper.countContainers())
                .build();
    }

    // 获取教师相关统计数据
    @Override
    public Statistics getTeacherStatistics(Long teacherId) {
        return new Statistics.Builder()
                .setCoursesCreatedByTeacher(statisticsMapper.countCoursesByTeacher(teacherId))
                .setEnrollmentsForTeacher(statisticsMapper.countEnrollmentsForTeacher(teacherId))
                .build();
    }

    // 获取课程难度等级分布
    @Override
    public List<Statistics> getCourseLevelStatistics() {
        return statisticsMapper.countCoursesByLevel();
    }

    // 获取课程时长统计
    @Override
    public Statistics getCourseDurationStatistics() {
        return statisticsMapper.getCourseDurationStats();
    }

    // 获取单门课程的选课人数
    @Override
    public Statistics getCourseEnrollmentsStatistics(Long courseId) {
        return new Statistics.Builder()
                .setEnrollmentsForCourse(statisticsMapper.countEnrollmentsForCourse(courseId))
                .build();
    }

    // 获取选课趋势统计
    @Override
    public Statistics getEnrollmentTrendStatistics() {
        return new Statistics.Builder()
                .setEnrollmentsByWeek(statisticsMapper.countEnrollmentsThisWeek())
                .setEnrollmentsByMonth(statisticsMapper.countEnrollmentsThisMonth())
                .build();
    }

    // 获取容器状态统计
    @Override
    public List<Statistics> getContainerStatusStatistics() {
        return statisticsMapper.countContainersByStatus();
    }

    // 获取容器使用时长统计
    @Override
    public Statistics getContainerDurationStatistics() {
        return statisticsMapper.getContainerDurationStats();
    }
}